package com.sijibao.amap;

import android.os.Parcel;
import android.os.Parcelable;

import com.amap.api.location.AMapLocation;


/**
 * 
 * 上传坐标
 * {"latitude":30556301,"longitude":114310446
 * ,"locateTime":1395286095,"region":"湖北省"
 * ,"city":"武汉市","county":"武昌区","street":"徐东大街"
 * ,"streetNumber":"徐东1路凯旋门广场A座"}]}
 * 
 * 
 * @author JiangLiangJun
 *
 */
public class MyAmapLocation implements Parcelable{
	
	
	/**
	 * 海拔mile
	 */
	public double altitude;
	public long latitude;
	public long longitude;
	public long locateTime;
	public String region;
	public String city;
	public String county;
	public String street;
	public String streetNumber;
	public String address;
	
	public double latitude_d;
	public double longitude_d;
	
	public MyAmapLocation(){
		
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeDouble(altitude);
		dest.writeLong(latitude);
		dest.writeLong(longitude);
		dest.writeDouble(latitude_d);
		dest.writeDouble(longitude_d);
		dest.writeLong(locateTime);
		dest.writeString(region);
		dest.writeString(city);
		dest.writeString(county);
		dest.writeString(street);
		dest.writeString(streetNumber);
		dest.writeString(address);
		
	}
	
	private static final Creator<MyAmapLocation> CREATOR = new Creator<MyAmapLocation>() {

		@Override
		public MyAmapLocation createFromParcel(Parcel source) {
			// TODO Auto-generated method stub
			MyAmapLocation location = new MyAmapLocation();
			location.altitude = source.readDouble();
			location.latitude = source.readLong();
			location.longitude = source.readLong();
			location.latitude_d = source.readDouble();
			location.longitude_d = source.readDouble();
			location.locateTime = source.readLong();
			location.region = source.readString();
			location.city = source.readString();
			location.county = source.readString();
			location.street = source.readString();
			location.streetNumber = source.readString();
			location.address=source.readString();
			return location;
		}

		@Override
		public MyAmapLocation[] newArray(int size) {
			// TODO Auto-generated method stub
			return new MyAmapLocation[size];
		}
	};
	
	public static MyAmapLocation amapLocationToMy(AMapLocation location){
		MyAmapLocation mylocation = new MyAmapLocation();
		mylocation.altitude = location.getAltitude();//mile
		mylocation.locateTime = location.getTime()/1000;
		mylocation.longitude = (long) (location.getLongitude()*1e6);
		mylocation.latitude = (long) (location.getLatitude()*1e6);
		mylocation.longitude_d = location.getLongitude();
		mylocation.latitude_d = location.getLatitude();
		mylocation.city = location.getCity();
		mylocation.region =  location.getProvince();
		mylocation.county =  location.getDistrict();
		mylocation.street = "";
		mylocation.streetNumber = "";
		mylocation.address=location.getAddress();
		return mylocation;
	}

}
